package work20241226;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author zdl
 * @date 2024/12/26
 */
public class Demo17 {
    public static void main(String[] args) {
        //17. 创建一个定时线程池，安排一个任务在3秒后执行，任务打印当前时间。
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(3);
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        String s = sdf.format(new Date());
        System.out.println("当前时间:"+s);
        pool.schedule(new Runnable() {
            @Override
            public void run() {
                SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
                String s = sdf.format(new Date());
                System.out.println("线程:"+s);
            }
        }, 3, TimeUnit.SECONDS);
    }
}
